<template>
	<view style="width: 100%;overflow: hidden;">
		<view class="" v-if="isFirst">
			<logingNot :xuankeImg="xkImg" :moniImg="nmImg" :openUrl1="openUrl1" :openUrl2="openUrl2" v-if="!isLogin"></logingNot>
			<loging :xuankeImg="xkImg" :moniImg="nmImg" :openUrl1="openUrl1" :openUrl2="openUrl2" v-else></loging>
		</view>
		<view class="" v-if="isSecond===1">
			<PlanDetail :isShowBtn="isShowBtn"></PlanDetail>
		</view>
		<view class="" v-if="isSecond===2">
			<BuyDetail :isShowBtn="isShowBtn"></BuyDetail>
		</view>
	</view>
</template>

<script>
	import PlanDetail from './components/planDetail.vue'
	import logingNot from './components/logingNot.vue'
	import loging from './components/loging.vue'
	import BuyDetail from './components/buyDetail.vue'
	import {
		TOAST
	} from "../../util/util";
	import {
		CHECK_TOKEN
	} from '../../util/util'
	import {
		request
	} from "../../util/api";
	export default {
		components: {
			logingNot,
			loging,
			PlanDetail,
			BuyDetail
		},
		data() {
			return {
				isLogin: CHECK_TOKEN(),
				xkImg: "",
				nmImg: "",
				openUrl: "",
				// 用户评测到期时间
				isBuy: "",
				isFirst: true,
				isSecond: 0,
				isShowBtn: true,
				openUrl1:"",
				openUrl2:"",
			};
		},
    onShow(){
		  if(this.isLogin){
			 this.$store.commit('getGlobalData') 
		  }else{
			  return
		  }
    },
		onLoad() {
			// this.getList()
			this.getData()
			this.getHandel()
		},
		methods: {
			// 获取选科要求和模拟填报数据
			getData() {
				request({
					url: '/system/wx/CompassAppExplore/list',
					method: "get",
					token: true,
					platfom: 'weixin'
				}).then(res => {
					const img = res
					for (let itemTitle of img) {
						if (itemTitle.title === '选科要求') {
							this.xkImg = itemTitle.homeImage
							this.openUrl1=itemTitle.url
						}
						if (itemTitle.title === '模拟填报') {
							this.nmImg = itemTitle.homeImage
							this.openUrl2=itemTitle.url
						}
					}
				})
			},
			// 获取当前登录数据
			getUserInfoData() {
				request({
					url: '/app/userCenter/getLoginUserInfo',
				}).then(res => {
					this.isBuy = res.data.endEvaluateTime
					// 判断用户测评到期时间
					if (this.isBuy != null && this.isBuy !== "") { //用户已登录已购买
						// 隐藏登录/去测评页面
						this.isFirst = false
						this.getReport()
					}
				})
			},
			getHandel() {
				let isLoging = CHECK_TOKEN()
				// 判读是否登录
				if (!isLoging) { //未登录
					this.title = "去登录"
				} else { //已登录 
					this.title = "去测评"
					this.getUserInfoData()
				}
			},
			// 判断是否有测评报告
			getReport() {
				request({
					url: '/wx/getUserReportIs',
					method: 'post'
				}).then(res => {
					// 未生成报告
					if (res.data != 0) {
						this.isSecond = 1
						if (res.data === 1) {
							// 未提交报告
							this.isShowBtn = true
						} else if (res.data===3) {
							this.isSecond = 2
							this.isShowBtn=false
						} else {							
							this.isShowBtn = false
						}
					} else {
						this.isSecond = 2
					}
				})
				if (this.isSecond != 2 && !this.isFirst) {
					this.isSecond = 1
				}
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
